﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.SA
{
    public partial class zj_job_edit : PageBase
    {

        string sid = "";
        public string us,um,tab="zj_job";
        public BLL.SC.zjjob jbs = new BLL.SC.zjjob();

        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            um = Session["user"].ToString();
            if (!IsPostBack)
            {

                if (!string.IsNullOrEmpty(Request["sid"]))
                {
                    sid = Request["sid"].Trim();

                    hidsid.Text = sid;
                    fill();
                    BindText(sid);
                }
               

            }

        }

        void fill()
        {
            //公司分类
            DataTable e = BLL.Bllbase.get_table("[zj]");
            ddlzj.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlzj.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["zname"].ToString().Trim(), e.Rows[i]["zbh"].ToString().Trim()));
            }
            ddlzj.DataBind();

            DataTable d = jbs.GetList("sid=" + sid + "").Tables[0];
            ddlzj.SelectedIndex = ddlzj.Items.IndexOf(ddlzj.Items.FindByValue(d.Rows[0]["zbh"].ToString()));
            ddltype.SelectedIndex = ddltype.Items.IndexOf(ddltype.Items.FindByValue(d.Rows[0]["ztype"].ToString()));
        }

        void BindText(string sid)
        {
            DataTable dt = jbs.GetList("sid=" + sid).Tables[0];

            if (dt.Rows.Count > 0)
            {
                hidsid.Text = dt.Rows[0]["sid"].ToString();
                hidbh.Text = dt.Rows[0]["zbh"].ToString();


                string rdate = dt.Rows[0]["sdate"].ToString().Trim();
                if (rdate.Substring(0, 4) != "1900")
                {
                    DateTime lastday = DateTime.Parse(rdate);
                    date1.Text = lastday.ToString("yyyy-M-d");
                }


                string edate = dt.Rows[0]["edate"].ToString().Trim();
                if (rdate.Substring(0, 4) != "1900")
                {
                    DateTime lastday = DateTime.Parse(edate);
                    date2.Text = lastday.ToString("yyyy-M-d");
                }
                

                memo.Text =(dt.Rows[0]["zmemo"].ToString());                           
            
            }

        }

      
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.SC.zjjob jb = new Model.SC.zjjob();

            jb.sid =int.Parse(hidsid.Text);
            jb.jbh = hidbh.Text; //岗位编号

            if (jb.jbh == "") return;

            jb.zbh = ddlzj.SelectedValue;
            jb.zname = ddlzj.SelectedText;
            jb.ztype = ddltype.SelectedValue;


            if (string.IsNullOrEmpty(date1.Text))
                date1.Text = "1900-01-01";

            if (string.IsNullOrEmpty(date2.Text))
                date2.Text = "1900-01-01";

            jb.sdate = DateTime.Parse(date1.Text.Trim());
            jb.edate = DateTime.Parse(date2.Text.Trim());

            jb.zmemo = HttpUtility.HtmlEncode(memo.Text);

            BLL.SC.zjjob sco = new BLL.SC.zjjob();
            sco.Update(jb);
            //更新业务员操作记录
            BLL.Bllbase.update_rec(tab, um, " jbh='" + jb.jbh + "' ");
            Alert.Show("修改完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());       
        }

       
    }
}